//mine.js
const app = getApp()
const util = require('../../utils/util.js')

Page({
  data: {
    avatarUrl: '',
    realName: '',
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
  },
  onLoad: function (options) {
    let that = this
    wx.getUserInfo({
      success(res) {
        console.log(res.userInfo)
        app.globalData.userInfo.avatarUrl = res.userInfo.avatarUrl;
        app.globalData.userInfo.nickName = res.userInfo.nickName;
        that.setData({
          avatarUrl: app.globalData.userInfo.avatarUrl || '',
          nickName: app.globalData.userInfo.nickName || '',
        })
      }
    })
  },
  onReady: function () {
    // Do something when page ready.
    let that = this;
    if(!app.globalData.windowHeight){
      wx.getSystemInfo({
        complete: (res) => {
          app.getWindowHeight(res);
          that.setData({
            scrollHeight:app.getScrollHeight(200)
          })
        },
      })
    }
  },
  onShow: function () {
    // Do something when page show.
  },
  onHide: function () {
    // Do something when page hide.
  },
  onUnload: function () {
    // Do something when page close.
  },
  onPullDownRefresh: function () {
    // Do something when pull down
  },
  bindGetUserInfo: function (e) {
    var that = this;
    console.log('bindGetUserInfo',e)
    if (e.detail.userInfo) {
      that.setData({
        nickName: e.detail.userInfo.nickName,
        avatarUrl: e.detail.userInfo.avatarUrl
      })
      app.globalData.userInfo.avatarUrl = e.detail.userInfo.avatarUrl;
      app.globalData.userInfo.nickName = e.detail.userInfo.nickName;
    }
  },
})